package proxy.cglib;


import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class ProxyStar implements MethodInterceptor{

    public Object getProxyInstance(){
        //字节码增强器
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(RealStar.class);
        enhancer.setCallback(this);
        return enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        System.out.println("啊~~你在哪儿");
        Object object = methodProxy.invokeSuper(o, args);
        System.out.println("啊~~我看不见");
        return object;
    }
}
